/*
* $Id: VisualManager.cpp 2 2009-12-23 13:58:02Z volok-aleksej@yandex.ru $
*
* Copyright 2008 by Volokitin Alexey
* All rights reserved
*
*/
#include "Common/include.h"
#include "VisualManager.h"
#include "MainWin.h"
#include "Settings/SettingsVisualComponent.h"

CVisualManager::CVisualManager()
{
	m_pMainWin = NULL;
	std::vector<IComponent*> aComponents = IApplication::GetApp()->GetComponents();
	for(std::vector<IComponent*>::const_iterator it = aComponents.begin(); it != aComponents.end(); it++)
		m_aVisualComponents.insert(std::make_pair((*it)->GetNameComponent(), (*it)->GetVisualComponent()));
}
CVisualManager::~CVisualManager(){}

IWnd* CVisualManager::GetMainWindow()
{
	if(!m_pMainWin)
	{
		std::vector<IVisualComponent*> aVisualComponents;
		for(std::map<std::tstring, IVisualComponent*>::iterator it = m_aVisualComponents.begin(); it != m_aVisualComponents.end(); it++)
			aVisualComponents.push_back(it->second);
		m_pMainWin = new CMainWin(aVisualComponents);
	}
	return dynamic_cast<IWnd*>(m_pMainWin);
}
IVisualComponent* CVisualManager::GetVisualComponent(const std::tstring& strComponentName)
{
	std::map<std::tstring, IVisualComponent*>::iterator it = m_aVisualComponents.find(strComponentName);
	if(it == m_aVisualComponents.end()){
		return NULL;}
	return it->second;
}
void CVisualManager::Free()
{
	delete this;
}

void CVisualManager::UpdateVisualComponents()
{
	for(std::map<std::tstring, IVisualComponent*>::iterator it = m_aVisualComponents.begin(); it != m_aVisualComponents.end(); it++)
		it->second->UpdateComponent();
}